package com.jr.service.impl;

import com.jr.mapper.PetOwnerMapper;
import com.jr.pojo.PetOwner;
import com.jr.service.PetOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PetOwnerServiceImpl implements PetOwnerService {

    @Autowired
    private PetOwnerMapper petOwnerMapper;

    @Override
    public boolean addPetOwner(PetOwner petOwner) {
        petOwner.setCreatedAt(LocalDateTime.now());
        petOwner.setUpdatedAt(LocalDateTime.now());
        return petOwnerMapper.insertPetOwner(petOwner) > 0;
    }

    @Override
    public PetOwner getPetOwnerById(Integer ownerId) {
        return petOwnerMapper.selectById(ownerId);
    }

    @Override
    public PetOwner getPetOwnerByUserId(Integer userId) {
        return petOwnerMapper.selectByUserId(userId);
    }

    @Override
    public boolean updatePetOwner(PetOwner petOwner) {
        petOwner.setUpdatedAt(LocalDateTime.now());
        return petOwnerMapper.updatePetOwner(petOwner) > 0;
    }

    @Override
    public List<PetOwner> getAllPetOwners() {
        return petOwnerMapper.selectAll();
    }

    @Override
    public boolean dropPetOwner(Integer ownerId) {
        return petOwnerMapper.dropPetOwner(ownerId)>0;
    }
}
